package bookManageSystem.dao;

import bookManageSystem.po.Admin;
import bookManageSystem.po.Employee;

import java.sql.*;

public class AdminDAO {

    private static final String USER = "root";
    private static final String PASS = "123456";
    private static final String DB_URL = "jdbc:mysql://localhost:3306/huaide?useUnicode=true&characterEncoding=UTF-8";

    private Connection getConnection() throws SQLException {
        return DriverManager.getConnection(DB_URL, USER, PASS);
    }




    public Admin getAdminByName(String username) {
        Admin admin = null;
        String sql = "SELECT * FROM admins WHERE adminName  = ?";
        try (Connection conn = getConnection();
             PreparedStatement stmt = conn.prepareStatement(sql)) {
            stmt.setString(1, username);
            try (ResultSet rs = stmt.executeQuery()) {
                if (rs.next()) {
                    admin = new Admin();
                    admin.setAdminId(rs.getInt("adminId"));
                    admin.setAdminName(rs.getString("adminName"));
                    admin.setPassword(rs.getString("password"));

                }
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return admin;
    }
}
